package com.hzb.erp.api.pc.clazz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzb.erp.api.pc.clazz.entity.Classroom;
import com.hzb.erp.api.pc.clazz.mapper.ClassroomMapper;
import com.hzb.erp.api.pc.clazz.pojo.ClassroomParamDTO;
import com.hzb.erp.api.pc.clazz.pojo.ClassroomSaveDTO;
import com.hzb.erp.api.pc.clazz.pojo.ClassroomVO;
import com.hzb.erp.api.pc.clazz.service.ClassroomService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 教室 服务实现类
 * </p>
 *
 * @author Ryan
 */
@Service
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom> implements ClassroomService {

    @Override
    public IPage<ClassroomVO> getList(ClassroomParamDTO param) {
        return this.baseMapper.getList(new Page<>(param.getPage(), param.getPageSize()), param);
    }

    @Override
    public Boolean saveOrUpdateByDTO(ClassroomSaveDTO dto) {
        Classroom item = new Classroom();
        BeanUtils.copyProperties(dto, item);
        if(item.getId() == null) {
            // 创建时所属学校是创建者的所属学校
            item.setSchoolId(dto.getSchoolId());
        }
        return this.saveOrUpdate(item);
    }

}
